
$(function(){
	$.get('/s/workflow/service?action=listSession&id='+$("#cid").val(), function(data) {
	    
		var dataSource = new kendo.data.DataSource({
			  data: data
		});
		var grid = $("#grid").data("kendoGrid");
		grid.setDataSource(dataSource);
		grid.refresh();
	});
	
	$("#grid").kendoGrid({
        scrollable: true,
        sortable: false,
        filterable: false,
        pageable: {
            input: false,
            numeric: false
        },
        columns: [
            { field: "date", title: "Date", width: "180px",format: "{0:dd/MM/yyyy}"},
            { field: "morning", title: "Morning", width: "130px",template: '<input type="checkbox" class="Morning" #= !morning ? "disabled=disabled" : "" # />' },
            { field: "afternoon", title: "Afternoon", width: "130px",template: '<input type="checkbox" class="Afternoon" #= !afternoon ? "disabled=disabled" : "" # />' },
            { field: "evening", title:"Evening", width: "130px",template: '<input type="checkbox" class="Evening" #= !evening ? "disabled=disabled" : "" # />' }
        ]
	});
});

function submitFreeSlots(){
	var cells = new Array();
	$("tbody tr").each(function(){
		var date = $(this).find("td").html();
		var morning = $(this).find(".Morning").is(":checked");
		var afternoon = $(this).find(".Afternoon").is(":checked");
		var evening = $(this).find(".Evening").is(":checked");
		var availslot = {date:date,slots:[morning,afternoon,evening]};
		cells.push(availslot);
	});
	$("#availslot").val(JSON.stringify(cells));
}